package me.jayramafisher.mcsurvival;

import org.jnbt.Tag;
import java.io.File;
import java.util.TreeMap;
import org.jnbt.CompoundTag;

//File: PermissionManager.java
//Description: managers player's permissions related to private land, etc.
//Last date of modification (yyyymmdd): 20110716
//NOTE: the structure for the permissions file has not been determined yet.
//    A group manager and a land manager may replace this class.

/**
*The PermissionManager class is used to verify players' actions. This class is instantiated by SurvivalPlugin and frequently called by the event handlers.
*/

public class PermissionManager
{

    private SurvivalPlugin plugin;
    private CompoundTag data;
    private static final String fileLocation = "plugins/MCSurvival/permissions.nbt";

    public void PermissionManager(SurvivalPlugin nplugin)
    {
        plugin = nplugin;
        try
        {
            if((new File(fileLocation)).exists()) data = (CompoundTag)NBTManager.load(new File(fileLocation));
            else data = new CompoundTag("permissions",new TreeMap<String,Tag>());
        } catch(Exception e)
        {
            data = null;
        }
        if(data == null) plugin.log.println("Error: PermissionManager failed to load the permissions file.");
        else plugin.log.println("Error: PermissionManager started successfully.");
    }

    public void onDisable()
    { 
        try
        {
            NBTManager.save(new File(fileLocation),data);
            data = null;
        } catch (Exception e)
        {
            plugin.log.println("Error: PermissionManager failed to save the permissions file.");
        }
    }
	
	////

}
